<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>线下还款申请资金明细 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="wrapper">
    <div class="insOfflineFundDtlForm">
        <form id="insOfflineFundDtl_form">
            <div class="fieldset1 tabel_col tabel_col_2 clearFix">
                <div class="caption">
                    <span class="title">还款申请信息</span>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">还款申请ID</div>
                    <div class="field">
                        <span id="applyLogId" name="applyLogId">${insOfflineRepayLogVO.id}</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">贷款合同号</div>
                    <div class="field">
                        <span id="crCntNo" name="crCntNo">${insOfflineRepayLogVO.crCntNo}</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">还款金额</div>
                    <div class="field">
                        <span id="repayAmt" name="repayAmt">&yen;${insOfflineRepayLogVO.repayAmt/100} </span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">还款状态</div>
                    <div class="field">
                        <input name="applyStsCd" id="applyStsCd" data-value="${insOfflineRepayLogVO.applyStsCd}" placeholder="请选择" ltype="combobox">
                    </div>
<%--                        <select name="applyStsCd" id="applyStsCd" data-value="${insOfflineRepayLogVO.applyStsCd}"--%>
<%--                                validate="{required:true,select:true}" class="l-selected">--%>
<%--                            <option value=" ">--请选择--</option>--%>
<%--                            <c:forEach items="${applyStsCdList}" var="item">--%>
<%--                                <option value="${item.key }">${item.value }</option>--%>
<%--                            </c:forEach>--%>
<%--                        </select>--%>

                </div>
            </div>

            <div id="searchButtonBox" name="searchButtonBox" class="searchButtonBox">
                <span id="searchCapFundBtn" class="sq-button sq-button-round">查找客户可用资金</span>
                <span id="saveInsOfflineFundDtl_Btn" class="sq-button sq-button-round" hidden="hidden">发起还款</span>
<%--                <span id="saveInsOfflineFundDtl_Btn" class="sq-button sq-button-hasicon 10-dialog-btn-ok"><i class="sqBtnIco_10"></i>保存</span>--%>
            </div>
        </form>
    </div>
    <div id="ligergrid" class="sq-grid"></div>
</div>
<script>
    var grid = null, menu = null;
    $(function() {
        var _applyLogId = "${insOfflineRepayLogVO.id}";//主键ID
        var _applyStsCd = "${insOfflineRepayLogVO.applyStsCd}";//还款申请状态
        var _repayAmt = ${insOfflineRepayLogVO.repayAmt};

        if (_applyStsCd == '0') {
            $("#searchButtonBox").attr("style","text-align:center;display: block;");
        } else {
            $("#searchButtonBox").attr("style","text-align:center;display: none;");
        }

        grid = $("#ligergrid").ligerGrid({
			url: '<%=path%>/repay/insOfflineFundDtl/initList.do',
			parms:{applyLogId:_applyLogId},
			method: 'get',
			columns: [
				{display: '资金编号', name: 'code', width: 130, align: 'left', enabledSort: false,
<%--					render:function(rowdata,index,value){--%>
<%--						return '<a href="javascript:;" style="cursor: pointer;" onclick="qyFund('+rowdata.id+')">'+rowdata.code+'</a>';--%>
<%--					}--%>
				},
				{display: '收款名称', name: 'acceptName', minWidth: 100, align: 'left', enabledSort: false},
				{display: '收款账号', name: 'acceptCode', minWidth: 80, align: 'left', enabledSort: false},
				{display: '交易(到账)日期', name: 'acceptDate', width: 100, align: 'center', enabledSort: false,render:renderDate},
				{display: '客户名称', name: 'cstNm', width: 90, align: 'left', enabledSort: false,},
				{display: '来款账号', name: 'comeCode', minWidth: 80, align: 'left', enabledSort: false},
				{display: '来款户名', name: 'comeName', width: 100, align: 'left', enabledSort: false},
				{display: '来款金额', name: 'amount', width: 90, align: 'right', enabledSort: false,
					render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.amount/100);
					}
				},
				{display: '可用金额', name: 'availableAmount', width: 90, align: 'right', enabledSort: false,
					render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.availableAmount/100);
					}
				},
			],
			usePager: false,
			root: 'rows',
			record: 'total',
			hideLoadButton: true,
			width: '100%',
			height: '100%',
			heightDiff: -2,
			checkbox: true,
			rownumbers: true,
			allowUnSelectRow: true,
			alternatingRow: true
		});
		grid.setHeight(300);

        $("#applyStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });

        $("#insOfflineFundDtl_form").ligerForm({
            validate: true
        });

        liger.get("applyStsCd").setData(${applyStsCdList});
        liger.get("applyStsCd").setDisabled();
        /*可用资金列表*/
        $("#searchCapFundBtn").click(function (event) {
            grid = $("#ligergrid").ligerGrid({
                url: '<%=path%>/capital/capFund/queryCapFund.do',
                parms:{applyLogId:_applyLogId},
                method: 'get',
                columns: [
                    {display: '资金id', name: 'id', minWidth: 100, align: 'left', enabledSort: false, hide: true},
                    {display: '资金编号', name: 'code', width: 130, align: 'left', enabledSort: false,
<%--                        render:function(rowdata,index,value){--%>
<%--                            return '<a href="javascript:;" style="cursor: pointer;" onclick="qyFund('+rowdata.id+')">'+rowdata.code+'</a>';--%>
<%--                        }--%>
                    },
                    {display: '收款名称', name: 'acceptName', minWidth: 100, align: 'left', enabledSort: false},
                    {display: '收款账号', name: 'acceptCode', minWidth: 80, align: 'left', enabledSort: false},
                    {display: '交易(到账)日期', name: 'acceptDate', width: 100, align: 'center', enabledSort: false,render:renderDate},
                    {display: '客户名称', name: 'cstNm', width: 90, align: 'left', enabledSort: false,},
                    {display: '来款账号', name: 'comeCode', minWidth: 80, align: 'left', enabledSort: false},
                    {display: '来款户名', name: 'comeName', width: 100, align: 'left', enabledSort: false},
                    {display: '来款金额', name: 'amount', width: 90, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.amount/100);
                        }
                    },
                    {display: '可用金额', name: 'availableAmount', width: 90, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.availableAmount/100);
                        }
                    },
                ],
                usePager: false,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: '100%',
                heightDiff: -2,
                checkbox: true,
                rownumbers: true,
                allowUnSelectRow: true,
                alternatingRow: true
            });
		});

        /*保存*/
        $("#saveInsOfflineFundDtl_Btn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }

            var _capFunds = [];
            var _capFund;
            var fundUseAmt = 0;
            for (var index in selectedRows) {
                _capFund = new Object();
                _capFund.fundId = selectedRows[index].id;
                _capFund.fundCd = selectedRows[index].code;
                _capFund.useAmt = selectedRows[index].availableAmount;

                _capFunds.push(_capFund);

                fundUseAmt = fundUseAmt + _capFund.useAmt;
            }

            if (_repayAmt != fundUseAmt) {
                $.ligerDialog.SQalert({content: "资金可用金额之和必须等于还款金额", SQ_type: "warning"});
                return;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {capFunds:JSON.stringify(_capFunds),applyLogId: _applyLogId},
                url: '<%=path%>/repay/insOfflineFundDtl/add.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                        $("#searchButtonBox").attr("style","text-align:center;display: none;");
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    });

        //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }


</script>
</body>
</html>
